import 'package:flutter/material.dart';
import '../definitions/color.dart';
import 'focus_manage/focus_widget.dart';
import 'letter.dart';

class LetterCard extends StatefulWidget {
  final String value;
  final FocusNode focusNode;
  final bool? autofocus;
  final void Function()? onConfirm;

  LetterCard({
    super.key,
    required this.value,
    this.autofocus,
    this.onConfirm,
    FocusNode? focusNode,
  }) : focusNode = focusNode ?? FocusNode();

  @override
  State<LetterCard> createState() => _LetterCardState();
}

class _LetterCardState extends State<LetterCard> {
  @override
  Widget build(BuildContext context) {
    bool showFocusStatus = widget.focusNode.hasFocus;
    return FocusWidget(
        focusNode: widget.focusNode,
        autofocus: widget.autofocus,
        onConfirm: widget.onConfirm,
        onFocusChange: (bool value) {
          setState(() {});
        },
        child: LetterLineBox(
          letter: widget.value,
          color: showFocusStatus ? SchemeColor.seedColor.value : null,
        ));
  }
}
